<?php
/**
 * | @author 韩威兵^life <1877361302@qq.com>
 * +----------------------------------------------------------------------
 * | @copyright 2016 - 2019 HQ
 * +----------------------------------------------------------------------
 * | @version $Id: 2019/4/23 16:04 jiahe_new JiaheAdminStoreUser.php 韩威兵^life $
 * +----------------------------------------------------------------------
 */

namespace app\common\common\model;

use think\Model;

class  JiaheAdminStoreUser extends Model {
    protected $table = 'jiahe_admin_store_user';


    /**
     * 增加一条数据
     * @param $admin_id
     * @param $user_id
     * @return int|string
     */
    public function insertByAdminUserId($admin_id, $user_id){
        $data['admin_id'] = $admin_id;
        $data['user_id'] = $user_id;
        return $this->insertGetId($data);
    }

    /**
     * 通过新平台的id，查找旧平台用户id
     * @param $id
     */
    public function findByNewAdminId($id){
        $where['admin_id'] = $id;
        return $this->where($where)->findToArray();
    }

    /**
     * 通过新平台的id，修改旧平台的id
     * @param $admin_id
     * @param $user_id
     * @return false|int
     */
    public function updateByNewAdminId($admin_id, $user_id){
        $field = $this->findByNewAdminId($admin_id);
        if(empty($field)){
            $id = $this->insertByAdminUserId($admin_id, $user_id);
            return $id;
        }
        $where['admin_id'] = $admin_id;
        $data['user_id'] = $user_id;
        return $this->save($data, $where);
    }
}  